]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
switcherPopup: Move to a ClutterGesture for closing the popup
authorJonas Dreßler <verdre@v0yd.nl>
Sun, 13 Jul 2025 10:01:10 +0000 (12:01 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 28 Aug 2025 17:14:06 +0000 (19:14 +0200)
When the user presses a mouse button outside of the switcherPopup, the
popup should close. This broke when we moved StButton to ClutterGesture,
because the button_press_event() handler in switcherPopup will close the
popup before the click gesture recognizes.

Since we're trying to move away from direct event handling anyway, port
this functionality to a LongPressGesture with a duration of 0, so that
the popup closes immediately on button press as it used to.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2853>

js/ui/switcherPopup.js

index 3af9188a5b156e7cd59f58dc88fec1b6434abaac..790ac091ec10f28512bb0c98f0486e70520a2324 100644 (file)
@@ -68,6 +68,22 @@ export const SwitcherPopup = GObject.registerClass({
             coordinate: Clutter.BindCoordinate.ALL,
         }));
 
+        const longPressGesture = new Clutter.LongPressGesture({
+            long_press_duration_ms: 0,
+        });
+        longPressGesture.connect('may-recognize', () => {
+            const coords = longPressGesture.get_coords_abs();
+            const actorAtCoords =
+                global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, coords.x, coords.y);
+
+            return !this._switcherList?.contains(actorAtCoords);
+        });
+        longPressGesture.connect('recognize', () => {
+            // User clicked outside
+            this.fadeAndDestroy();
+        });
+        this.add_action(longPressGesture);
+
         // Initially disable hover so we ignore the enter-event if
         // the switcher appears underneath the current pointer location
         this._disableHover();
@@ -223,12 +239,6 @@ export const SwitcherPopup = GObject.registerClass({
         return Clutter.EVENT_STOP;
     }
 
-    vfunc_button_press_event() {
-        /* We clicked outside */
-        this.fadeAndDestroy();
-        return Clutter.EVENT_PROPAGATE;
-    }
-
     _scrollHandler(direction) {
         if (direction === Clutter.ScrollDirection.UP)
             this._select(this._previous());